package com.ymatou.iapi.godfreight.testcase;

import java.security.interfaces.RSAMultiPrimePrivateCrtKey;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.godfreight.parameter.queryCollectionGoodsAddressInfoBean;
import com.ymatou.iapi.godfreight.service.queryCollectionGoodsAddressInfoCall;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.CollectiongoodsAddress;
import com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper;
import com.ymttest.utils.TestDataManager;
/**
*商户自提点详情
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_queryCollectionGoodsAddressInfo{
	private static queryCollectionGoodsAddressInfoBean bean;
	private static queryCollectionGoodsAddressInfoCall call;
	private CollectionGoodsWapper CollectionGoodsWapper=new CollectionGoodsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户自提点详情");
	}

	@Before
	public void caseUp() {
		bean=new queryCollectionGoodsAddressInfoBean();
		call=new queryCollectionGoodsAddressInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws JSONException
	{
		Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
		List<CollectiongoodsAddress> list=CollectionGoodsWapper.selectCollectiongoodsAddress(bean.getAddressId(), bean.getSellerId());
		Logger.verifyEquals(1, list.size(), "验证一条数据");
		CollectiongoodsAddress db_address=list.get(0);
		JsonObject exp_obj=call.getData();
		Logger.verifyEquals(exp_obj.get("addressName").getAsString(), db_address.getAddressName(), "验证返回的AddressName与数据库collectiongoods_address中的字段AddressName一致");
		Logger.verifyEquals(exp_obj.get("addressType").getAsInt(), db_address.getAddressType(), "验证返回的AddressName与数据库AddressType中的字段AddressType一致");
		Logger.verifyEquals(exp_obj.get("baseAddress").getAsString(), db_address.getBaseAddress(), "验证返回的AddressName与数据库baseAddress中的字段baseAddress一致");
		Logger.verifyEquals(exp_obj.get("detailAddress").getAsString(), db_address.getDetailAddress(), "验证返回的AddressName与数据库DetailAddress中的字段DetailAddress一致");
		Logger.verifyEquals(exp_obj.get("phone").getAsString(), db_address.getAreaCode()+"-"+db_address.getMobile(), "验证返回的AddressName与数据库phone中的字段Mobile一致");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_001() {
		Logger.start(true,"商户自提点详情-商家配置自提");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerId(mchId_channl);
            bean.setAddressId(addressId);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_002() {
		Logger.start(true,"商户自提点详情-商家未配置自提,但是设置自提点");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            
            bean.setSellerId(mchId_channl);
            bean.setAddressId(addressId);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_003() {
		Logger.start(true,"商户自提点详情-商家设置2个自提点,查询第一次设置");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            
            //添加二个自提地址
             createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            
            bean.setSellerId(mchId_channl);
            bean.setAddressId(addressId);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_003_1() {
		Logger.start(true,"商户自提点详情-商家设置2个自提点,查询第二次设置");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            
            //添加二个自提地址
             createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            
            bean.setSellerId(mchId_channl);
            bean.setAddressId(addressId2);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();	

			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_005() {
		Logger.start(true,"商户自提点详情-sellerId=0");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerId(0);
            bean.setAddressId(addressId);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_006() {
		Logger.start(true,"商户自提点详情-sellerId为空");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
          //  bean.setSellerId(0);
            bean.setAddressId(addressId);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_007() {
		Logger.start(true,"商户自提点详情-addressId=0");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerId(mchId_channl);
            bean.setAddressId(0);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_008() {
		Logger.start(true,"商户自提点详情-addressId为空");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerId(mchId_channl);
           // bean.setAddressId(0);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_009() {
		Logger.start(true,"商户自提点详情-sellerId为空,addressId为空");
		try {
            
           // bean.setSellerId(mchId_channl);
           // bean.setAddressId(0);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_queryCollectionGoodsAddressInfo_010() {
		Logger.start(true,"商户自提点详情-sellerId=0,addressId=0");
		try {
            
            bean.setSellerId(0);
            bean.setAddressId(0);
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}